$(function () {
	pageInit();
});
function pageInit(){
	$("#jqGrid").jqGrid({
	    url: baseURL + 'apiFailed',
	    datatype: "json",
	    colModel: [			
	        { label: '编号', name: 'sid', width: 30, key: true },
	        { label: '服务名称',name:'serviceName', width: 80},
	        { label: '服务类别',name:'categoryCode', width: 75 },
	        { label: '服务商名称',name:'releaseName', width: 100 },
	        { label: '发布时间',name:'releaseTime',  width: 80},
	        { label: '服务状态',name:'serviceState', width: 25, formatter: function(value, options, row){
					if(value == 0){
						return '<span class="label label-default">待审核</span>';
					}else if(value ==1){
						return '<span class="label label-success">已通过</span>';
					}else{
						return '<span class="label label-danger">未通过</span>';
					}
				}}
	    ],
		viewrecords: true,
	    height: 385,
	    rowNum: 10,
	    sortname : 'sid',
		rowList : [10,30,50],
	    rownumbers: false, 
	    rownumWidth: 25, 
	    autowidth:true,
	    multiselect: true,
	    pager: "#jqGridPager",
	    jsonReader : {
	        root: "page.list",
	        page: "page.pageNum",
	        total: "page.pages",
	        records: "page.total"
	    },
	    prmNames : {
	        page:"page", 
	        rows:"limit", 
	        order: "order"
	    },
	    gridComplete:function(){
	    	//隐藏grid底部滚动条
	    	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
	    }
	});
};

var vm = new Vue({
	el:'#rrapp',
	data:{
		q:{
			key: null
		},
		showList: true,
		title:null,
		service:{
			sid:null,
			serviceName:null,
			categoryCode:null,
			releaseName:null,
			releaseTime:null
		}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		pending: function(){
			var sid = getSelectedRow();
			debugger
			if(sid == null){
				return false;
			}
			var ret = $("#jqGrid").jqGrid('getRowData', sid);
			debugger
			vm.showList = false;
			vm.title = "服务审核";
			vm.service.sid=ret.sid;
			vm.service.serviceName=ret.serviceName;
			vm.service.categoryCode=ret.categoryCode;
			vm.service.releaseName=ret.releaseName;
			vm.service.releaseTime=ret.releaseTime;
		},
	    reload: function () {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		},
		btnPassOrfail:function(){
			debugger
			var sid=vm.service.sid
			if(event){
				var status=event.target.getAttribute("status")
				debugger
			}
			var msg=""
			if(status==1){
				msg='确定要通过审核？'
			}else{
				msg='确定要拒绝审核？'
			}
			confirm(msg, function(){
				$.post(baseURL+"passOrfailService",{"sid":sid,"status":status},function(result){
					alert("操作成功");
					vm.reload();
				});
			});

		}
	}
});